import React from "react";
import { InboxOutlined, UploadOutlined } from '@ant-design/icons';
import { message, Upload, Button } from 'antd';
import { useState } from "react";
import http from "@/utils/http";
import { UPLOADFILE_API } from "@/api";
const { Dragger } = Upload;

const XxUploadFile = ({ onFinish = Function,onRemove=Function }) => {
    const [loading, setLoading] = useState(false);

    // 自定义上传
    const customRequest = async (params) => {
        console.log("自定义上传：\n", params)
        setLoading(true)
        const { file, filename, onProgress, onSuccess, onError } = params;

        http.upload({
            url: UPLOADFILE_API,
            before: () => setLoading(true),
            params: {
                file: file,
                filename: filename,
            },
            success: (res) => {
                console.log("上传成功", res)
                // const { fileDirPath, fileName, fileSize, fileType } = res?.data
                onSuccess()
                onFinish(res?.data)
            },
            failure: (msg) => {
                onError()
                console.log("上传失败：" + msg)
            },
            complete: () => setLoading(false)
        })


    }


    return (
        <>

            <Upload
                customRequest={customRequest}
                onRemove={onRemove}
                maxCount={1}
                multiple={false}

            >
                <Button loading={loading} icon={<UploadOutlined />}>文件上传</Button>
            </Upload>
        </>
    )
}
export default XxUploadFile;